<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Roomfacilities
 * This class represents a data access object for the database table 'roomfacilities'.
 */
class Roomfacilities {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: facilityId, type: int, is nullable: false
	 */
	private $facilityId  = 0;

	/**
	 * associated database field: roomId, type: int, is nullable: false
	 */
	private $roomId  = 0;

	/**
	 * associated database field: hotelId, type: int, is nullable: false
	 */
	private $hotelId  = 0;

	private $facilities = null;

	private $rooms = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("RoomFacilities");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['facilityId'])) $this->facilityId = $row['facilityId'];
		if(isset($row['roomId'])) $this->roomId = $row['roomId'];
		if(isset($row['hotelId'])) $this->hotelId = $row['hotelId'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Roomfacilities
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'facilityId: '.(($escapeQuotationMarks===true) ? addslashes($this->facilityId) : $this->facilityId).', ';
		$s .= 'roomId: '.(($escapeQuotationMarks===true) ? addslashes($this->roomId) : $this->roomId).', ';
		$s .= 'hotelId: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelId) : $this->hotelId);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Roomfacilities
	 */
	public function toJSONString(){
		$fieldValues = array ("facilityId"=>$this->facilityId, "roomId"=>$this->roomId, "hotelId"=>$this->hotelId);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Roomfacilities object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"roomfacilities\">\n";
		$htmlCode .= '	<div class="roomfacilities_facilityId">'.(($escapeHTML===true) ? htmlspecialchars($this->facilityId) : $this->facilityId)."</div>\n";
		$htmlCode .= '	<div class="roomfacilities_roomId">'.(($escapeHTML===true) ? htmlspecialchars($this->roomId) : $this->roomId)."</div>\n";
		$htmlCode .= '	<div class="roomfacilities_hotelId">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelId) : $this->hotelId)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/


	public static function loadAll(){
		$roomfacilities = new Roomfacilities();
		$rows = $roomfacilities->dao->getData("");
		$roomfacilitiess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roomfacilities();
			$d->init($rows[$index]);
			array_push($roomfacilitiess,$d);
		}
		return $roomfacilitiess;
	}


	/**
	 * Load the Roomfacilities uniquely by its primary key.
	 * @param facilityId the primary key
	 * @param hotelId the primary key
	 * @param roomId the primary key
	 * @return Roomfacilities Instance of {@link Roomfacilities}
	 */
	public static function loadUnique($facilityId, $roomId, $hotelId){
		$roomfacilities = new Roomfacilities();
		$rows = $roomfacilities->dao->getData("`facilityId`='$facilityId' AND `roomId`='$roomId' AND `hotelId`='$hotelId'");
		$roomfacilities->init($rows[0]);
		return $roomfacilities;
	}


	/**
	 * Load all records of Roomfacilities uniquely by its foreign keys:
	 * roomId, hotelId
	 * @param roomId foreign key
	 * @param hotelId foreign key
	 * @return array of Instance of {@link Roomfacilities}
	 */
	public static function loadByFKRoomidHotelid($roomId, $hotelId){
		$roomfacilities = new Roomfacilities();
		$rows = $roomfacilities->dao->getData("`roomId`='$roomId' AND `hotelId`='$hotelId'");
		$roomfacilitiess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roomfacilities();
			$d->init($rows[$index]);
			array_push($roomfacilitiess,$d);
		}
		return $roomfacilitiess;
	}


	/**
	 * Load all records of Roomfacilities uniquely by its foreign keys:
	 * facilityId
	 * @param facilityId foreign key
	 * @return array of Instance of {@link Roomfacilities}
	 */
	public static function loadByFKFacilityid($facilityId){
		$roomfacilities = new Roomfacilities();
		$rows = $roomfacilities->dao->getData("`facilityId`='$facilityId'");
		$roomfacilitiess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roomfacilities();
			$d->init($rows[$index]);
			array_push($roomfacilitiess,$d);
		}
		return $roomfacilitiess;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("facilityId"=>$this->facilityId, "roomId"=>$this->roomId, "hotelId"=>$this->hotelId);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("facilityId"=>$this->facilityId, "roomId"=>$this->roomId, "hotelId"=>$this->hotelId);
		$where = "`facilityId`='$facilityId' AND `roomId`='$roomId' AND `hotelId`='$hotelId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['facilityId'])){
			$this->facilityId = $_POST['facilityId'];
		}
		if (isset($_POST['roomId'])){
			$this->roomId = $_POST['roomId'];
		}
		if (isset($_POST['hotelId'])){
			$this->hotelId = $_POST['hotelId'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['facilityId'])){
			$this->facilityId = $_GET['facilityId'];
		}
		if (isset($_GET['roomId'])){
			$this->roomId = $_GET['roomId'];
		}
		if (isset($_GET['hotelId'])){
			$this->hotelId = $_GET['hotelId'];
		}
	}


	/**
	 * Returns the value from the database field facilityId.
	 * In the database the field facilityId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getFacilityId(){
		return $this->facilityId;
	}


	/**
	 * Set the value from the database field facilityId.
	 * In the database the field facilityId is of type int.
	 * The database field is NOT nullable.
	 * @param facilityId String with the value for the field to be set
	 */
	public function setFacilityId($facilityId){
		$this->facilityId = $facilityId;
	}


	/**
	 * Returns the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomId(){
		return $this->roomId;
	}


	/**
	 * Set the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @param roomId String with the value for the field to be set
	 */
	public function setRoomId($roomId){
		$this->roomId = $roomId;
	}


	/**
	 * Returns the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getHotelId(){
		return $this->hotelId;
	}


	/**
	 * Set the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @param hotelId String with the value for the field to be set
	 */
	public function setHotelId($hotelId){
		$this->hotelId = $hotelId;
	}


	/**
	 * Returns an instance of the linked Facilities object.
	 * A One to Many (1:n) relation exists between the Roomfacilities and the Facilities table.
	 * @return Facilities the linked instance of Facilities
	 */
	public function getFacilities(){
		if($this->facilities == null){
			$this->facilities = Facilities::loadUnique($this->facilityId);
		}
		return $this->facilities;
	}


	/**
	 * Set a link to a related Facilities instance
	 * @param targetObjectInstanceName instance of Facilities to be linked to this object instance
	 */
	public function setFacilities($facilities){
		$facilities->facilityId = $this->facilityId;
		$this->facilities = $facilities;
	}


	/**
	 * Returns an instance of the linked Rooms object.
	 * A One to Many (1:n) relation exists between the Roomfacilities and the Rooms table.
	 * @return Rooms the linked instance of Rooms
	 */
	public function getRooms(){
		if($this->rooms == null){
			$this->rooms = Rooms::loadUnique($this->roomId);
		}
		return $this->rooms;
	}


	/**
	 * Set a link to a related Rooms instance
	 * @param targetObjectInstanceName instance of Rooms to be linked to this object instance
	 */
	public function setRooms($rooms){
		$rooms->roomId = $this->roomId;
		$this->rooms = $rooms;
	}
}
?>